import subprocess
import sys

xmms2Cflags, xmms2Cflagse = subprocess.Popen(["pkg-config", "--cflags", "xmms2-client"],
    stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

visualCflags, visualCflagse = subprocess.Popen(["pkg-config", "--cflags", "libvisual-0.4"],
    stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

if xmms2Cflagse or visualCflagse:
    print xmms2Cflagse
    print visualCflagse
    sys.exit(0)

output = "%s %s" % (xmms2Cflags, visualCflags)

env = Environment(CCFLAGS = Split("-g -Wall " + output))

xmms2Ldflags, xmms2Ldflagse = subprocess.Popen(["pkg-config", "--libs", "xmms2-client"],
    stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

visualLdflags, visualLdflagse = subprocess.Popen(["pkg-config", "--libs", "libvisual-0.4"],
    stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

if xmms2Ldflagse or visualLdflagse:
    print xmms2Ldflagse
    print visualLdflagse
    sys.exit(0)

output = "%s %s" % (xmms2Ldflags, visualLdflags)

libs = env.ParseFlags(Split(output));
env.MergeFlags(libs)

plugin = env.SharedLibrary(["input_xmms2.c"]);

env.Install("/usr/lib/libvisual-0.4/input/", plugin);
env.Alias('install', '/usr/lib/libvisual-0.4/input')
